/**************************************************************************
 *
 * Copyright (C) 2007 University of California, Los Angeles.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 *************************************************************************/

package edu.ucla.cs.typecast.app.auction;

import java.io.*;
import java.util.*;

/**
 * An auction listing representing one ongoing or closed auction.
 */

public class ListingInfo implements Comparable, Serializable {
	/**
	 * Serial number for serialization.
	 */

	private static final long serialVersionUID = 1L;

	/**
	 * Compare two objects.
	 * 
	 * @param o1
	 * @param o2
	 * @return
	 */

	protected static boolean eq(Object o1, Object o2) {
		return (o1 == null && o2 == null) || (o1.equals(o2));
	}

	/**
	 * Item info.
	 */

	protected ItemInfo itemInfo;

	/**
	 * Price.
	 */

	protected int price;

	/**
	 * End date.
	 */

	protected Date endDate;

	/**
	 * Seller.
	 */

	protected ParticipantInfo sellerInfo;

	/**
	 * Highest bidder (null if item is not bid on).
	 */

	protected ParticipantInfo highestBidderInfo;

	public ListingInfo(ItemInfo itemInfo, int price, Date endDate,
			ParticipantInfo sellerInfo) {
		super();
		this.itemInfo = itemInfo;
		this.price = price;
		this.endDate = endDate;
		this.sellerInfo = sellerInfo;
		this.highestBidderInfo = null;
	}
	
	public int compareTo(Object o) {
		if (o instanceof ListingInfo && endDate != null) {
			return endDate.compareTo(((ListingInfo) o).endDate);
		} else {
			return 0;
		}
	}

	public boolean equals(Object o) {
		// Compare item info only

		if (o instanceof ListingInfo) {
			ListingInfo li = (ListingInfo) o;
			return eq(itemInfo, li.itemInfo);
		} else {
			return false;
		}
	}

	public Date getEndDate() {
		return endDate;
	}

	public ParticipantInfo getHighestBidderInfo() {
		return highestBidderInfo;
	}

	public ItemInfo getItemInfo() {
		return itemInfo;
	}

	public int getPrice() {
		return price;
	}

	public ParticipantInfo getSellerInfo() {
		return sellerInfo;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public void setHighestBidderInfo(ParticipantInfo highestBidder) {
		this.highestBidderInfo = highestBidder;
	}

	public void setItemInfo(ItemInfo itemInfo) {
		this.itemInfo = itemInfo;
	}

	public void setPrice(int price) {
		this.price = price;
	}

	public void setSellerInfo(ParticipantInfo sellerInfo) {
		this.sellerInfo = sellerInfo;
	}
}
